import React, {Component} from 'react';
import Child1 from "./components/Child1";
import Child2 from "./components/Child2";
import Child3 from "./components/Child3";
import Preview from "./Calculator/Preview";
import Key from "./Calculator/Key";

class Day03 extends Component {
  state = {
    hello: '来自老父亲的问候',
    num: 0
  };

  callback(msg){//要在子组件中触发
    //this
    console.log('儿子说:', msg);
    console.log('老父亲被触动了');
  }

  receiveKey = (key) => {
    //传递到另外一个子组件
    console.log(key);

    //this.setState is not a function
    // console.log(this)
    //改变this的指向  要让当前this指向 组件实例
    this.setState({
      num: key
    })
  };

  // 处理虚拟dom的
  render() {
    let {num} = this.state;
    return (
      <div>
        {/*
          vue
          <Child1 :name='值'/>
        */}
        {/*<Child1 msg={hello}/>*/}
        {/*<Child2 callback={this.callback}/>*/}
        {/*<Child3>*/}
        {/*  <h1>hello Im your father</h1>*/}
        {/*</Child3>*/}

        {/*计算器显示的组件*/}
        <Preview num={num}/>

        {/*点击按钮的组件*/}
        <Key receiveKey={this.receiveKey}/>

      </div>
    );
  }
}

export default Day03;
